﻿//扫描
function StartScan() {
    var FileNo = $("#divLB table tbody tr.selected td:eq(1) a").text();
    var savePath = "D:\\智能录单\\" + FileNo + "\\";
    var ImgName = "";
    DemoCtrl.BeginScan(0, savePath, ImgName, 1);
}

//选择扫描仪
function ScanSelect() {
    //DemoCtrl.SelectScanner();
    $("#DemoCtrl")[0].SelectScanner();
}

//获取是否加纸
function ScanState() {
    //0表示缺纸，1表示有纸
    alert(DemoCtrl.ScannerState());
}

//GetScanners
function GetScanners() {
    var arr, scanners;
    scanners = DemoCtrl.GetScanners();
    arr = scanners.split("|");
    for (var i = 0; i < arr.length; i++) {
        alert(arr[i])
    }
    //设置获取到的第一个扫描仪
    DemoCtrl.SetScanner(arr[0]);
    //显示当前扫描仪
    alert(DemoCtrl.ScannerName);
}

//合并pdf
function ToPdf() {
    var NewPdfPath = "C:\\SimpleScan\\NewPdf.pdf";
    var SrcFile = document.getElementById("filePath").value;
    DemoCtrl.SaveAsPdf(NewPdfPath, SrcFile);
}

//合并pdf返回base64
function ToPdfBase64() {
    var SrcFile = document.getElementById("filePath").value;
    NewPdfPath = DemoCtrl.SaveFilesToPdfBase64(SrcFile);
    alert(NewPdfPath);
}

function EndScan(path) {
    alert(path);
    //var arr;
    //arr = path.split("|");
    //for (var i = 0; i < arr.length; i++) {
    //    //alert(arr[i])
    //    var code = DemoCtrl.GetBase64(arr[i]);
    //    var listimg = document.getElementById("imglist");
    //    var li = document.createElement("li");
    //    var img = document.createElement("img");
    //    img.src = "data:image/jpeg;base64," + code;
    //    img.width = "300";
    //    img.height = "400";
    //    li.appendChild(img);
    //    listimg.appendChild(li);
    //}
}

//指定文件夹合并pdf
function FolderToPdfBase64() {
    var SrcFile = "c:\\1";
    var saveFile = "c:\\1\\1.pdf";
    NewPdfPath = DemoCtrl.FolderToPdfBase64(SrcFile, 2, saveFile, false);
    alert(NewPdfPath);
}

//获取扫描文件
function GetAllFile() {
    DataLoading();
    var path = DemoCtrl.GetAllFile();
    var arr = path.split("|");

    var _imgData = "";//图片的base64编码
    var _dirName = $("#divLB tr.selected a").text();//目录名称
    var _FID = $("#divLB tr.selected a").attr("FID");

    for (var i = 0; i < arr.length; i++) {
        var code = DemoCtrl.GetBase64(arr[i]);
        if (i == 0) {
            _imgData += code.substring(0, code.length - 1);
        }
        else {
            _imgData += "❤" + code.substring(0, code.length - 1);
        }
    }

    $.ajax({
        type: "post",
        url: "ashx/ImgGet.ashx",
        dataType: "json",
        async: true,
        cache: false,
        data: { type: "SaveImage", FID: _FID, imgData: _imgData, dirName: _dirName },
        success: function (msg) {
            //if (msg.result == 1) {
            //    $("#tabPage tbody").append(msg.strHtml);
            //    $("#sTotal").html(msg.count);
            //    $("#htmlTip").remove();
            //    $("#tabPage tbody tr:last").click();
            //}
            //else {
            //    alert(msg.errMsg);
            //    $("#htmlTip").remove();
            //}
            location.href = location.href;
        }
    })
}

//GetScanStu
function GetScanStu() {
    alert(DemoCtrl.GetScannerState());
}

//SetNUM
function SetNUM() {
    DemoCtrl.ScanNameNum = 3;
    alert(DemoCtrl.ScanNameNum);
}



